package com.outstanding.his.revisit.facade;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.outstanding.his.patient.domain.Patient;
import com.outstanding.his.patient.service.IPatientService;
import com.outstanding.his.revisit.domain.Revisit;
import com.outstanding.his.revisit.service.IRevisitService;
import com.outstanding.his.util.pager.Pagination;

@Controller
@SessionAttributes("patient")
public class RevisitController {

	private IRevisitService revisitService;
	private IPatientService patientService;

	public void setRevisitService(IRevisitService revisitService) {
		this.revisitService = revisitService;
	}

	public void setPatientService(IPatientService patientService) {
		this.patientService = patientService;
	}

	@RequestMapping("/revisit/list.do")
	public String revisitList(@RequestParam("patientId") Integer patientId,
			Model model) {
		Patient patient = patientService.getPatient(patientId);
		Pagination pagination = new Pagination(20);
		pagination.setTotalCount(50);
		model.addAttribute("pagination", pagination);
		model.addAttribute("patient", patient);
		return "/revisit/list";
	}
	
	@RequestMapping("/revisit/view.do")
	public String revisitView(@ModelAttribute("patient") Patient patient,
			@RequestParam("revisitId") Integer revisitId, Model model) {
		Revisit revisit = revisitService.getRevisit(revisitId);
		model.addAttribute("revisit", revisit);
		return "/revisit/view";
	}
	
}
